package com.itheima.service.impl;

import com.itheima.entity.Clazz;
import com.itheima.entity.PageBean;
import com.itheima.mapper.ClassMapper;
import com.itheima.service.ClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class ClassServicelmpl implements ClassService {
    @Autowired
    ClassMapper classMapper;
    @Override
    public PageBean pageQuery(Integer page, Integer pageSize) {
        Integer count = classMapper.count();
        page = (page - 1) * pageSize;
        List<Class> studentList = classMapper.pageQuery(page, pageSize);


        PageBean pageBean = new PageBean();
        pageBean.setTotal((count));
        pageBean.setRows(studentList);
        return pageBean;
    }
    //根据id删除
    @Override
    public void delete(List<Integer> id) {
        classMapper.delete(id);
    }
    //添加员工
    @Override
    public void saveClass(Clazz clazz) {
        clazz.setCreateTime(LocalDateTime.now());
        clazz.setUpdateTime(LocalDateTime.now());
        classMapper.insert(clazz);
    }
}
